﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using ECCIT;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Configuration;

public partial class GateService_HomeVideoInterface : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "text/xml";
        Response.ContentEncoding = Encoding.UTF8;

        string output = string.Empty;
        try
        {
            ResultInfo valRes = ValidateArguments();

            if (valRes.Result)
            {
                string sLangID = Request.Params["lang"];
                int langID = (string.IsNullOrEmpty(sLangID)) ? 2052 : int.Parse(sLangID);
                HomeVideoBll bll = new HomeVideoBll();
                List<HomeVideo> models = bll.GetAllModList();
                if (models.Count == 0) throw new Exception("No video.");
                output = string.Format("<video name=\"{0}\" url=\"{1}\"></video>", models[0].VideoUrl, ConfigCacheManager.FilePath.UploadMediaPath.VirtualPath + "/" + models[0].VideoUrl);
            }
        }
        catch (Exception ex)
        {
            output = "<files value=\"false\"></files>";
        }

        Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + output);
    }

    private ResultInfo ValidateArguments()
    {
        ResultInfo result = new ResultInfo(false);
        string sLangID = Request.Params["lang"];
        if (string.IsNullOrEmpty(sLangID)) return result;

        int langID;
        bool b = int.TryParse(sLangID, out langID);
        if (!b) return result;
        if (langID != 2052 && langID != 1033) return result;

        result.Result = true;
        return result;
    }
}